import 'package:ez_ic_led/tool/assets.dart';
import 'package:flutter/material.dart';
import 'package:flutter_kit_plus/flutter_kit.dart';

class SliderItem extends StatefulWidget {
  String name;
  double min;
  double max;
  double value;
  bool nameDown;
  Function(double)? onChange;
  SliderItem(
      {super.key,
      required this.name,
      required this.min,
      required this.max,
      required this.value,
      this.nameDown = true,
      required this.onChange});

  @override
  State<SliderItem> createState() => _SliderItemState();
}

class _SliderItemState extends State<SliderItem> {
  Widget getName() {
    return Text(widget.name, style: const TextStyle(fontSize: 12, color: Colors.white));
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        widget.nameDown ? Container(height: 0.01) : getName(),
        Expanded(
            child: kSlider(
          dirction: Axis.horizontal,
          value: widget.value,
          min: widget.min,
          max: widget.max,
          thumbColor: Colors.white,
          activeColor: Color_left,
          inActiveColor: Colors.black,
          onChanged: (p0) {
            setState(() => widget.value = p0);
          },
          onChangedForSend: widget.onChange,
        )),
        widget.nameDown
            ? getName()
            : Text('${widget.value.toInt()}', style: const TextStyle(fontSize: 12, color: Colors.white)),
      ],
    );
  }
}
